package com.hundsun.yr.universal.p2p.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;



/**
 * @Title: BaselineTextView.java 
 * @Description: 底对齐TextView
 * @date 2016-1-12 上午11:16:04 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class BaselineTextView extends TextView {

    public BaselineTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaselineTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs);
        setIncludeFontPadding(false); //remove the font padding
        setGravity(Gravity.BOTTOM);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        TextPaint textPaint = getPaint();
        textPaint.setColor(getCurrentTextColor());
        textPaint.drawableState = getDrawableState();
        canvas.save();

        int yOffset = getHeight() - getBaseline();
        canvas.translate(0, yOffset / 2);

        super.onDraw(canvas);
        canvas.restore();
    }
}
